﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace ankietyzacja.Dao
{
    public class MailingDao : Dao
    {


        public MailingDao(SqlConnection c, SqlTransaction t) : base(c, t)
        {
        }

       

        public Int32 usunWyslanaAnkieta(Int32 emailId)
        {
            String sql =
         "DELETE FROM WYSLANAANKIETA" +
           " WHERE EMAIL_ID = @EMAIL_ID";


            SqlCommand command = new SqlCommand(sql, connection, transaction);
            command.Parameters.Add(new SqlParameter("@EMAIL_ID", emailId));

            return command.ExecuteNonQuery();

        }



        public Int32 usunUzytkownikXEmail(Int32 emailId)
        {
            String sql =
                    "DELETE FROM UZYTKOWNIK_x_EMAIL " +
               " WHERE EMAIL_ID = @EMAIL_ID";


            SqlCommand command = new SqlCommand(sql, connection, transaction);
            command.Parameters.Add(new SqlParameter("@EMAIL_ID", emailId));

            return command.ExecuteNonQuery();

        }

        public Int32 insertNewEmail()
        {
            String sql =
                @"
INSERT INTO EMAIL
           (TEMAT
           ,TRESC
           ,DATAWYSLANIA
           ,DATAUTWORZENIA)
     VALUES
           ('(tu wpisać temat e-maila)'
           ,'(tu wpisać treść e-maila)'
           ,null
           ,getDate()); SELECT scope_identity();
";


            SqlCommand command = new SqlCommand(sql, connection, transaction);

            return System.Convert.ToInt32(command.ExecuteScalar());


        }


    }


}